package cn.ac.cintcm.dao.hibernate.hsqldb;

import java.util.List;

import cn.ac.cintcm.dao.hibernate.UserDaoGeneric;
import cn.ac.cintcm.model.User;

/**
 * This class interacts with Spring's HibernateTemplate to save/delete and
 * retrieve User objects.
 *
*/
public class UserDaoHibernate extends UserDaoGeneric {

    /** 
     * {@inheritDoc}
    */
    @SuppressWarnings("unchecked")
	public List<User> getAttentionUser(Long id) {
    	String hsql = "select p from User u, User p, Therapy t where " +
    			"t.notify=0 and DATEDIFF('dd', t.tdate,CURDATE())>=(t.dosage + 2)" +
    			"and p.id=t.patient and u.id=" + id + " and p member of u.patients";
	    return  getHibernateTemplate().find(hsql);
	}

    /** 
     * {@inheritDoc}
    */
	@SuppressWarnings("unchecked")
	public List<User> getRecentUser(Long id) {
    	String hsql = "select distinct p from User u, User p, Therapy t " +
    			"where DATEDIFF('dd', t.tdate,CURDATE()) <=7 and p.id=t.patient and u.id=" + id + " and p member of u.patients";
	    return  getHibernateTemplate().find(hsql);
	}


}
